/* 
 *
 */
package com.cory.admin.sys.controller.test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cory.admin.sys.config.AdminConfig;
import com.cory.admin.sys.controller.portal.LoginController;
import com.cory.admin.sys.domain.entity.SysUser;
import com.cory.admin.sys.service.SysUserService;
import com.cory.boot.utils.CommonData;

/**
 * @author xiongcong
 * @date 2020-05-18
 */
@Controller
@RequestMapping("test")
public class AdminTestController extends LoginController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private AdminConfig adminConfig;

    @RequestMapping("session")
    @ResponseBody
    public String session(String loginName, String key, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        assertNotNull(key);
        if (!key.equals(CommonData.getStrParam("test_session_key"))) {
            return "error";
        }
        
        SysUser user = sysUserService.getByLoginName(StringUtils.defaultIfBlank(loginName, "admin"), adminConfig.getLoginUserType());
        super.successLoginHandle(request, response, session, user);
        
        return "success";
    }
}
